class cell {
  constructor() {
    this.state = "safe";
    this.surround = 0;
  }
  setDanger() {
    this.state = "danger";
  }
}

function init(arr) {
  arr.length = 9;
  for (let i = 0; i < arr.length; i++) {
    arr[i] = new Array(9);
    for (let j = 0; j < arr[i].length; j++) {
      arr[i][j] = new cell();
    }
  }
  return 0;
}

function print(arr) {
  for (let i = 0; i < arr.length; i++) {
    for (let j = 0; j < arr[i].length; j++) {
      console.log(arr[i][j].state);
    }
    console.log("\n");
  }
}

function setMine(arr) {
  for (let i = 1; i <= 9; i++) {
    // 随机埋雷
    let x = Math.floor(Math.random() * 9);
    let y = Math.floor(Math.random() * 9);
    arr[x][y].setDanger();

    // 增加数字
    // ---
    for (let m = x - 1; m <= x + 1; m++) {
      for (let n = y - 1; n <= y + 1; n++) {
        if (m >= 0 && m <= 8 && n >= 0 && n <= 8) arr[m][n].surround++;
      }
    }
    // ---
  }
}
